home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 February / Macworld (1999-02).dmg / Cinema 4D GO demo / Plugin / Modeling / EqualTangents.cof next >
Text File  |  1998-03-16  |  1KB  |  57 lines

  1. // EqualTangents
  2. // set all selected points of an Hermite Spline to the
  3. // same length, defined by the user
  4. // (c) Christian Losch
  5. // 1997 Maxon Computer GmbH
  6.  
  7. var len_vl,len_vr;
  8.  
  9. Function(doc)
  10. {
  11.     var i,num,op,info,dlg,sp;
  12.  
  13.     // allocate all data
  14.     info = new (SplineInfo); if (!info) return;
  15.     sp   = new (SplinePoint); if (!sp) return;
  16.     dlg  = new (SimpleDialog); if (!dlg) return;
  17.  
  18.     // get active object
  19.     op = doc->FindFirstActiveObject(); if (!op || getclass(op)!=SplineObject) return;
  20.     op->GetSplineInfo(info);
  21.     if (info->type!=SPL_HERMITE)
  22.     {
  23.         TextDialog("No Hermite Spline");
  24.         return;
  25.     }
  26.  
  27.     // user dialog
  28.     dlg->SetTitle("EqualTangents");
  29.     dlg->SetData(0,"Left" ,FIELD_FLOAT,0.0,1E6,len_vl);
  30.     dlg->SetData(1,"Right",FIELD_FLOAT,0.0,1E6,len_vr);
  31.     if (!dlg->DoDialog()) return;
  32.  
  33.     len_vl = dlg->GetData(0);
  34.     len_vr = dlg->GetData(1);
  35.  
  36.     // change tangents
  37.     num = op->GetPointNumber();
  38.     for (i=0; i<num; i++)
  39.     {
  40.         if (op->IsPointSelected(i) && op->GetPoint(i,sp))
  41.         {
  42.             sp->vl = vnorm(sp->vl)*len_vl;
  43.             sp->vr = vnorm(sp->vr)*len_vr;
  44.             op->SetPoint(i,sp);
  45.         }
  46.     }
  47.  
  48.     op->UpdateObject();
  49.     doc->SendMessage(ACTIVE_OBJECT_CHANGED);
  50. }
  51.  
  52.  
  53. main()
  54. {
  55.     len_vl = len_vr = 50.0;
  56.     RegisterMenuHook("Equal Tangents","Function");
  57. }